package com.volcengine.example.visual;

import com.alibaba.fastjson.JSON;
import com.volcengine.model.request.AssumeRoleRequest;
import com.volcengine.model.response.AssumeRoleResponse;
import com.volcengine.service.sts.ISTSService;
import com.volcengine.service.sts.impl.STSServiceImpl;
import com.volcengine.service.visual.IVisualService;
import com.volcengine.service.visual.VisualDefaultClient;
import com.volcengine.service.visual.impl.VisualServiceImpl;
import com.volcengine.service.visual.model.request.VisualCertConfigInitRequest;
import com.volcengine.service.visual.model.request.VisualCertQueryProRequest;
import com.volcengine.service.visual.model.request.VisualCertTokenProRequest;
import com.volcengine.service.visual.model.request.VisualCertVerifyProRequest;
import com.volcengine.service.visual.model.response.VisualCertConfigInitResponse;
import com.volcengine.service.visual.model.response.VisualCertQueryProResponse;
import com.volcengine.service.visual.model.response.VisualCertTokenProResponse;
import com.volcengine.service.visual.model.response.VisualCertVerifyProResponse;

import java.util.ArrayList;
import java.util.Arrays;

public class CertVerifyProDemo {

    public static void main(String[] args) {

//       sts获取临时ak/sk
        sts();

        //获取IVisualService新实例
        //IVisualService visualService = VisualServiceImpl.getInstance();
        //获取全局的IVisualService实例
        IVisualService visualService = VisualDefaultClient.iVisualService;

        // call below method if you don't set ak and sk in ～/.vcloud/config
        visualService.setAccessKey("your ak");
        visualService.setSecretKey("your sk");
        //visualService.setSessionToken("123123123");
        //certTokenPro调用示例
        certTokenPro(visualService);
        //身份认证TokenPro服务V2（功能未改变）,返回全部response,无异常
        //certTokenProV2(visualService);

        // VerifyPro接口请求示例
        //verifyPro(visualService);
        // 身份认证VerifyPro服务V2（功能未改变）,返回全部response,无异常
        //verifyProV2(visualService);

        // QueryPro接口请求示例
        //queryPro(visualService);
        //身份认证QueryPro服务V2（功能未改变）,返回全部response,无异常
        //queryProV2(visualService);

        //Config接口调用示例
        tokenApiConfig(visualService);
        //身份认证Config服务V2（功能未改变）,返回全部response,无异常
        //tokenApiConfigV2(visualService);

    }


    //sts获取临时ak/sk
    public static void sts() {
        ISTSService stsService = STSServiceImpl.getInstance();

        stsService.setAccessKey("your ak");
        stsService.setSecretKey("your sk");

        AssumeRoleRequest request = new AssumeRoleRequest();
        request.setRoleSessionName("just_for_test");
        request.setDurationSeconds(900);
        request.setRoleTrn("trn:iam::yourAccountID:role/yourRoleName");

        AssumeRoleResponse resp = null;
        try {
            resp = stsService.assumeRole(request);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        System.out.println(JSON.toJSONString(resp));

    }

    //certTokenPro调用势力
    public static void certTokenPro(IVisualService visualService) {
        VisualCertTokenProRequest req = new VisualCertTokenProRequest();
        req.setReqKey("cert_pro_token");
        req.setStsToken("123123123");
        //req.setTosInfo();
        req.setRefSource("1");  // 0：无源，1：有源
        req.setIdcardName("xxx");
        req.setIdcardNo("xxx");
        VisualCertTokenProRequest.RiskMotionList riskMotionList = new VisualCertTokenProRequest.RiskMotionList();
        ArrayList<String> freeList = new ArrayList<>(Arrays.asList("0", "1"));
        riskMotionList.setFree(freeList);
        ArrayList<String> lowList = new ArrayList<>(Arrays.asList("0", "1", "2", "3"));
        riskMotionList.setFree(freeList);
        ArrayList<String> mediumList = new ArrayList<>(Arrays.asList("0", "1", "2", "3"));
        riskMotionList.setFree(freeList);
        ArrayList<String> highList = new ArrayList<>(Arrays.asList("0", "1", "2", "3"));
        riskMotionList.setFree(freeList);
        riskMotionList.setLow(lowList);
        riskMotionList.setMedium(mediumList);
        riskMotionList.setHigh(highList);
        req.setRiskMotionList(riskMotionList);
        req.setRefImage("/9xx");
        req.setMaxLivenessTrial(10);
        req.setLivenessTimeout(10);
        //req.setCallBackInfo();
        System.out.println(req.getRiskMotionCount());
        try {
            VisualCertTokenProResponse response = visualService.certTokenPro(req);
            System.out.println(JSON.toJSONString(response));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //身份认证TokenPro服务V2（功能未改变）,返回全部response
    public static void certTokenProV2(IVisualService visualService) {
        VisualCertTokenProRequest req = new VisualCertTokenProRequest();
        req.setReqKey("cert_pro_token");
        req.setStsToken("123123123");
//        req.setTosInfo();
        req.setRefSource("1");  // 0：无源，1：有源
        req.setIdcardName("xxx");
        req.setIdcardNo("xxx");
        VisualCertTokenProRequest.RiskMotionList riskMotionList = new VisualCertTokenProRequest.RiskMotionList();
        ArrayList<String> freeList = new ArrayList<>(Arrays.asList("0", "1"));
        riskMotionList.setFree(freeList);
        ArrayList<String> lowList = new ArrayList<>(Arrays.asList("0", "1", "2", "3"));
        riskMotionList.setFree(freeList);
        ArrayList<String> mediumList = new ArrayList<>(Arrays.asList("0", "1", "2", "3"));
        riskMotionList.setFree(freeList);
        ArrayList<String> highList = new ArrayList<>(Arrays.asList("0", "1", "2", "3"));
        riskMotionList.setFree(freeList);
        riskMotionList.setLow(lowList);
        riskMotionList.setMedium(mediumList);
        riskMotionList.setHigh(highList);
        req.setRiskMotionList(riskMotionList);
        req.setRefImage("/9xx");
        req.setMaxLivenessTrial(10);
        req.setLivenessTimeout(10);
        //req.setCallBackInfo();
        System.out.println(req.getRiskMotionCount());
        Object response = visualService.certTokenProV2(req);
        System.out.println(JSON.toJSONString(response));
    }
    // VerifyPro接口请求示例
    public static void verifyPro(IVisualService visualService) {
          VisualCertVerifyProRequest req = new VisualCertVerifyProRequest();
        req.setReqKey("cert_pro_src_verify");
        req.setBytedToken("");
        req.setRiskInfo("xxx");
        req.setSdkData("xx");
        try {
            VisualCertVerifyProResponse response = visualService.certVerifyPro(req);
            System.out.println(JSON.toJSONString(response));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //身份认证VerifyPro服务V2（功能未改变）,返回全部response
    public static void verifyProV2(IVisualService visualService) {
        VisualCertVerifyProRequest req = new VisualCertVerifyProRequest();
        req.setReqKey("cert_pro_src_verify");
        req.setBytedToken("");
        req.setRiskInfo("xxx");
        req.setSdkData("xx");
        Object response = visualService.certVerifyProV2(req);
        System.out.println(JSON.toJSONString(response));
    }
    // QueryPro接口请求示例
    public static void queryPro(IVisualService visualService) {
        VisualCertQueryProRequest req = new VisualCertQueryProRequest();
        req.setReqKey("cert_verify_query");
        req.setBytedToken("");
        req.setOmitData(false);
        req.setOmitImageData(false);
        req.setOmitVideoData(false);
        try {
            VisualCertQueryProResponse response = visualService.certQueryPro(req);
            System.out.println(JSON.toJSONString(response));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //身份认证QueryPro服务V2（功能未改变）,返回全部response
    public static void queryProV2(IVisualService visualService) {
        VisualCertQueryProRequest req = new VisualCertQueryProRequest();
        req.setReqKey("cert_verify_query");
        req.setBytedToken("");
        req.setOmitData(false);
        req.setOmitImageData(false);
        req.setOmitVideoData(false);
        Object response = visualService.certQueryProV2(req);
        System.out.println(JSON.toJSONString(response));
    }
    //Config接口调用示例
    public static void tokenApiConfig(IVisualService visualService) {
        VisualCertConfigInitRequest req = new VisualCertConfigInitRequest();
        req.setReqKey("cert_config_init");
        req.setConfigName("test1");
        VisualCertConfigInitRequest.TokenApiConfig tokenApiConfig = new VisualCertConfigInitRequest.TokenApiConfig();
        tokenApiConfig.setRefSource("1");
        tokenApiConfig.setLivenessType("motion");
        req.setTokenApiConfig(tokenApiConfig);
        try {
            VisualCertConfigInitResponse response = visualService.certConfigInit(req);
            System.out.println(JSON.toJSONString(response));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //身份认证Config服务V2（功能未改变）,返回全部response
    public static void tokenApiConfigV2(IVisualService visualService) {
        VisualCertConfigInitRequest req = new VisualCertConfigInitRequest();
        req.setReqKey("cert_config_init");
        req.setConfigName("test1");
        VisualCertConfigInitRequest.TokenApiConfig tokenApiConfig = new VisualCertConfigInitRequest.TokenApiConfig();
        tokenApiConfig.setRefSource("1");
        tokenApiConfig.setLivenessType("motion");
        req.setTokenApiConfig(tokenApiConfig);
        Object response = visualService.certConfigInitV2(req);
        System.out.println(JSON.toJSONString(response));

    }



}



